{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# numpy的函数实例练习"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1.np.random.choice(a, size=None, replace=True, p=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([9, 4, 5, 3])"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import numpy as np\n",
    "a = np.array([1,2,3,4,5,6,7,8,9,10])\n",
    "out = np.random.choice(a, 4, replace=False) # 4表示采样几个值，replace为True可以出现重复，a可以是列表或整数\n",
    "out"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 167,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 5, 10,  5,  9])"
      ]
     },
     "execution_count": 167,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.random.randint(0,10,4)     # [0,10)内随机采样4个数，可以重复 与np.random.choice(10,4)相同"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([3, 2, 0])"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.random.choice(5, 3, replace=False, p=[0.1, 0, 0.3, 0.6, 0])  # 按照概率p抽样，不重复"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2. np.argsort"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 183,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1.元素的排序: [0 1 2 2 3 4 4 6 7 8 9]\n",
      "2.元素排序的序号: [ 9  3  0  4  1  2 10  5  6  7  8]\n"
     ]
    }
   ],
   "source": [
    "a = np.array([2,3,4,1,2,6,7,8,9,0,4])\n",
    "print('1.元素的排序:', np.sort(a))\n",
    "print('2.元素排序的序号:', np.argsort(a))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 188,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[2, 2, 3, 3, 4]"
      ]
     },
     "execution_count": 188,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = np.array([2,3,4,1,2,6,7,8,9,0,4])\n",
    "list(a[np.array([0,0,1,1,2])])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3. Counter "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 366,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Counter({4: 8, 2: 1, 3: 1, 5: 1})\n",
      "[(4, 8)] 4\n"
     ]
    }
   ],
   "source": [
    "from collections import Counter,OrderedDict\n",
    "a = np.array([1,1,1,1,2,3,4,4,4,5])\n",
    "b = [2,3,4,4,4,4,4,4,4,4,5]\n",
    "count = Counter(b)         # 统计数据出现的频率，numpy的array和list都行\n",
    "print(count)\n",
    "print(count.most_common(1), count.most_common(1)[0][0])   # 获取票数最高的值"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 4. np.bincount"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "各个索引出现的次数: [1 2 3 1 0 0 1 1]\n",
      "出现最多次的索引: 2\n"
     ]
    }
   ],
   "source": [
    "a = [0,2,2,2,3,1,1,7,6]   # 先看最大值为7\n",
    "b = np.bincount(a)\n",
    "print('各个索引出现的次数:', b)          # 结果对应索引0->7\n",
    "print('出现最多次的索引:', np.argmax(b)) # 如果最大次数有多个，选索引较低的输出"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 5. np.transpose"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 516,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a的维度: (1, 8)\n",
      "[[1]\n",
      " [2]\n",
      " [3]\n",
      " [4]\n",
      " [5]\n",
      " [6]\n",
      " [7]\n",
      " [8]]\n",
      "转置后的维度: (8, 1)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "array([[ 1,  2,  3,  4,  5,  6,  7,  8],\n",
       "       [ 2,  4,  6,  8, 10, 12, 14, 16],\n",
       "       [ 3,  6,  9, 12, 15, 18, 21, 24],\n",
       "       [ 4,  8, 12, 16, 20, 24, 28, 32],\n",
       "       [ 5, 10, 15, 20, 25, 30, 35, 40],\n",
       "       [ 6, 12, 18, 24, 30, 36, 42, 48],\n",
       "       [ 7, 14, 21, 28, 35, 42, 49, 56],\n",
       "       [ 8, 16, 24, 32, 40, 48, 56, 64]])"
      ]
     },
     "execution_count": 516,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = np.array([[1,2,3,4,5,6,7,8]])\n",
    "print('a的维度:',a.shape)\n",
    "b = np.transpose(a)               # 对矩阵做转置\n",
    "b = a.transpose()                 # 转置有3种方式np.transpose() arr.transpose() arr.T\n",
    "b = a.T                    \n",
    "print(b)\n",
    "print('转置后的维度:', b.shape)\n",
    "np.dot(b,a)                       # 矩阵相乘\n",
    "# np.dot(a,b)\n",
    "b.dot(a)                          # 矩阵相乘有两种方式 np.dot()  arr.dot()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 6. np.stack"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 2 3]\n",
      " [4 5 6]]\n",
      "[[ 0  0  0]\n",
      " [-3 -3 -3]]\n"
     ]
    }
   ],
   "source": [
    "a = np.array([1,2,3])\n",
    "b = np.array([4,5,6]) \n",
    "c = np.stack((a,b)) # 默认行堆叠 vstack hstack\n",
    "bprint(c)\n",
    "print(a - c)        # 不同维度可以叠加，条件是a有一个维度是1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 103,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(2, 3, 1, 4)\n",
      "(3, 2, 1, 4)\n",
      "------\n",
      "(6, 1, 4)\n",
      "(3, 2, 4)\n"
     ]
    }
   ],
   "source": [
    "a = np.ones([3,1,4])\n",
    "b = np.zeros([3,1,4])\n",
    "# stack模式默认在前面增加一个维度来叠加,如果设置axis=1则在第二维增加新维度来叠加\n",
    "# !!!stack是增加该维度\n",
    "out = np.stack([a,b], axis=0)     # 先添加一个第一维，然后在第1维度上叠加,默认的操作\n",
    "print(out.shape)\n",
    "out = np.stack([a,b], axis=1)     # 先添加一个第二维，然后在第2维度上叠加\n",
    "print(out.shape)\n",
    "print('------')\n",
    "out = np.vstack([a,b])            # 在竖直方向，即第一维上直接叠加 ！！！不会创建新维度          \n",
    "print(out.shape)\n",
    "out = np.hstack([a,b])            # 在水平方向，即第二维上直接叠加 ！！！不会创建新维度 \n",
    "print(out.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 460,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[0 0 0]\n",
      " [9 9 9]]\n",
      "-----\n",
      "[9 9 9]\n",
      "-----\n",
      "[ 0 27]\n"
     ]
    }
   ],
   "source": [
    "out = np.square(a-c)       # 计算平方\n",
    "out = (a-c)**2\n",
    "print(out)  \n",
    "print('-----')\n",
    "print(np.sum(out, axis=0)) # 0表示使用行看法，对应按列求和\n",
    "print('-----')\n",
    "print(np.sum(out, axis=1)) # 2表示使用列看法，对应按行求和"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 7. np.diagonal"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 444,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[0 1 2]\n",
      " [3 4 5]\n",
      " [6 7 8]]\n",
      "get diag:\n",
      " (3,) [0 4 8]\n"
     ]
    }
   ],
   "source": [
    "a = np.array(list(range(9))).reshape(3,3)\n",
    "print(a)\n",
    "print('get diag:\\n', a.diagonal.shape, np.diagonal(a))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 8. broadcast"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 499,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1., 1., 1.],\n",
       "       [2., 2., 2.],\n",
       "       [3., 3., 3.],\n",
       "       [4., 4., 4.]])"
      ]
     },
     "execution_count": 499,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = np.array([1,2,3,4]).reshape(4,1)\n",
    "b = np.zeros((4,3))\n",
    "a+b         # 行相等，扩展列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 494,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1., 2., 3., 4.],\n",
       "       [1., 2., 3., 4.],\n",
       "       [1., 2., 3., 4.]])"
      ]
     },
     "execution_count": 494,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = np.array([1,2,3,4])\n",
    "b = np.zeros((3,4))\n",
    "a+b     # 列相等则扩展行"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 496,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[10.],\n",
       "       [10.],\n",
       "       [10.]])"
      ]
     },
     "execution_count": 496,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.sum(a+b, axis=1, keepdims=True)   # keepdims设为True可以保持维度"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 515,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1., 2., 3.],\n",
       "       [1., 2., 3.],\n",
       "       [1., 2., 3.]])"
      ]
     },
     "execution_count": 515,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = np.array([1,2,3])\n",
    "b = np.zeros((3,3))\n",
    "a+b    # 默认从行扩展，除非指定维度"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 523,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 523,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.ceil(8/2).astype('int64')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 9. numpy.array_split(ary, indices_or_sections, axis=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 529,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[array([0, 1, 2]), array([3, 4]), array([5, 6]), array([7, 8])]\n"
     ]
    }
   ],
   "source": [
    "a = np.arange(9)\n",
    "out = np.array_split(a, 4)      # 切分矩阵\n",
    "print(out)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 532,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0 1 2]\n"
     ]
    }
   ],
   "source": [
    "print(out[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 535,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[[1],\n",
       "        [2],\n",
       "        [3]],\n",
       "\n",
       "       [[4],\n",
       "        [5],\n",
       "        [6]]])"
      ]
     },
     "execution_count": 535,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = np.array([1,2,3]).reshape(3,1)\n",
    "b = np.array([4,5,6]).reshape(3,1)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1 0 2 3 4 0]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "(array([0, 2, 3, 4], dtype=int64),)"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = np.array([1,0,2,3,4,0])\n",
    "print(a)\n",
    "np.nonzero(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 120,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[5.75274406e-290 2.39848787e-145 1.00000000e+000]\n"
     ]
    }
   ],
   "source": [
    "# f = np.array([123, 456, 789]) # 例子中有3个分类，每个评分的数值都很大\n",
    "# p = np.exp(f) / np.sum(np.exp(f)) # 不妙：数值问题，可能导致数值爆炸\n",
    "# print(p)\n",
    "# 那么将f中的值平移到最大值为0：\n",
    "f -= np.max(f) # f becomes [-666, -333, 0]\n",
    "p = np.exp(f) / np.sum(np.exp(f)) # 现在OK了，将给出正确结果\n",
    "print(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 10. np.dot()与 * 的区别"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 119,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "向量的内积:\n",
      " [[ 7 10]\n",
      " [15 22]]\n",
      "向量对应元素的乘积:\n",
      " [[ 1  4]\n",
      " [ 9 16]]\n"
     ]
    }
   ],
   "source": [
    "a = np.array([[1,2],[3,4]])\n",
    "b =  np.array([[1,2],[3,4]])\n",
    "print('向量的内积:\\n', a.dot(b))\n",
    "print('向量对应元素的乘积:\\n', a*b)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 11. 批量访问指定元素"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 185,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0  1  2]\n",
      " [ 3  4  5]\n",
      " [ 6  7  8]\n",
      " [ 9 10 11]]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "array([[333,   1,   2],\n",
       "       [  3, 333,   5],\n",
       "       [  6,   7,   8],\n",
       "       [  9,  10,  11]])"
      ]
     },
     "execution_count": 185,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = np.arange(12).reshape(4,3)\n",
    "print(a)\n",
    "index = np.array([0,1])\n",
    "\n",
    "a[[0,1], [0,1]] =333\n",
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 186,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 8,  9, 12],\n",
       "       [10, 11, 13]])"
      ]
     },
     "execution_count": 186,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = np.array([[1,2,5],[3,4,6]])\n",
    "b = np.array([7,7]).reshape(2,1)\n",
    "a +b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 187,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0  1  2  3  4  5  6]\n",
      " [ 7  8  9 10 11 12 13]\n",
      " [14 15 16 17 18 19 20]\n",
      " [21 22 23 24 25 26 27]\n",
      " [28 29 30 31 32 33 34]\n",
      " [35 36 37 38 39 40 41]\n",
      " [42 43 44 45 46 47 48]]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "array([[ 0, -1,  2,  3,  4,  5,  6],\n",
       "       [ 7,  8, -1, 10, 11, 12, 13],\n",
       "       [14, 15, 16, 17, -1, 19, 20],\n",
       "       [21, 22, 23, -1, 25, 26, 27],\n",
       "       [28, 29, 30, 31, 32, 33, -1],\n",
       "       [35, 36, 37, 38, 39, 40, 41],\n",
       "       [42, 43, 44, 45, 46, 47, 48]])"
      ]
     },
     "execution_count": 187,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr = np.arange(49).reshape(7,7)\n",
    "a = np.array([1,2,4,3,6])\n",
    "print(arr)\n",
    "arr[range(len(a)),a] = -1\n",
    "arr[arr>0]\n",
    "arr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 192,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 0 3 0]\n",
      " [5 0 7 8]]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "(array([0, 0, 1], dtype=int64), array([1, 3, 1], dtype=int64))"
      ]
     },
     "execution_count": 192,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = np.array([[1,0,3,0],[5,0,7,8]])\n",
    "print(a)\n",
    "np.where(a == 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 205,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([5, 0, 2, 1])"
      ]
     },
     "execution_count": 205,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.random.choice(7,4, replace=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "import torch.nn as nn\n",
    "?nn.MSELoss"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$ \\ell(x, y) = L = \\{l_1,\\dots,l_N\\}^\\top, \\quad l_n = \\left( x_n - y_n \\right)^2 $$\n",
    "$$\\ell(x, y) = \\begin{cases}\n",
    "        \\operatorname{mean}(L), & \\text{if}\\; \\text{size_average} = \\text{True},\\\\\n",
    "        \\operatorname{sum}(L),  & \\text{if}\\; \\text{size_average} = \\text{False}.\n",
    "    \\end{cases}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([2, 1, 1], dtype=int64)"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = np.array([[1,2,3],[0,3,2],[0,3,2]])\n",
    "np.argmax(a, axis=1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 12. np.reshape按照顺序从左到右一条龙排列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0  1  2  3  4  5  6  7  8  9]\n",
      " [10 11 12 13 14 15 16 17 18 19]\n",
      " [20 21 22 23 24 25 26 27 28 29]\n",
      " [30 31 32 33 34 35 36 37 38 39]\n",
      " [40 41 42 43 44 45 46 47 48 49]\n",
      " [50 51 52 53 54 55 56 57 58 59]\n",
      " [60 61 62 63 64 65 66 67 68 69]\n",
      " [70 71 72 73 74 75 76 77 78 79]\n",
      " [80 81 82 83 84 85 86 87 88 89]\n",
      " [90 91 92 93 94 95 96 97 98 99]]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "array([[[[ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9],\n",
       "         [10, 11, 12, 13, 14, 15, 16, 17, 18, 19]],\n",
       "\n",
       "        [[20, 21, 22, 23, 24, 25, 26, 27, 28, 29],\n",
       "         [30, 31, 32, 33, 34, 35, 36, 37, 38, 39]],\n",
       "\n",
       "        [[40, 41, 42, 43, 44, 45, 46, 47, 48, 49],\n",
       "         [50, 51, 52, 53, 54, 55, 56, 57, 58, 59]],\n",
       "\n",
       "        [[60, 61, 62, 63, 64, 65, 66, 67, 68, 69],\n",
       "         [70, 71, 72, 73, 74, 75, 76, 77, 78, 79]],\n",
       "\n",
       "        [[80, 81, 82, 83, 84, 85, 86, 87, 88, 89],\n",
       "         [90, 91, 92, 93, 94, 95, 96, 97, 98, 99]]]])"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = np.arange(100).reshape(10,10)\n",
    "print(a)\n",
    "a.reshape(1,5,2,10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1.        , 2.71828183, 7.3890561 ])"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.exp(np.array([i for i in range(3)]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 1  3  4]\n",
      " [13  5  6]\n",
      " [ 0  8  9]]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "array([ 4, 13,  9])"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = np.array([[1,3,4],[13,5,6],[0,8,9]])\n",
    "print(a)\n",
    "np.max(a, axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0.        , -2.30258509, -2.30258509],\n",
       "       [ 1.09861229,  1.38629436,  1.60943791]])"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = np.array([[1,2,3],[4,5,6]])\n",
    "b = np.array([[2],[1]])"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
